<script setup lang="ts">
import { Api } from '@/assets/apis';
import { ref, onMounted } from 'vue'
import type { ClassifyType } from '@/typings'
import { Toast } from 'vant';
import { useRouter } from 'vue-router';

const ClassifyData = ref<Array<ClassifyType>>([])
const loading = ref(false)
const router = useRouter()

onMounted(async () => {
    Toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0,
    });
    let data = await Api.getClassify()

    ClassifyData.value = data.data

    console.log(ClassifyData.value);
    Toast.clear()
    loading.value = true
})

const detail = (a: string, title: string, channel: string) => {
    router.push(`/classify/id=${a}?title=${title}&channel=${channel}`)
}

const publish = (id: string, title: string) => {
    router.push(`/classify/id=${id}?title=${title}`)
}

</script>

<template>
    <div v-show="loading">
        <div class="men-list">
            <div class="title">
                <em class="sep"></em>
                {{ ClassifyData[0]?.name }}
            </div>
            <div class="content">
                <div class="item" v-for="a in ClassifyData[0]?.cates"
                    @click="detail(a.cateId, a.cateName, ClassifyData[0].channel)">
                    <div class="bg">{{ a.cateName }}</div>
                </div>
            </div>
        </div>
        <div class="space"></div>
        <div class="men-list">
            <div class="title">
                <em class="sep"></em>
                {{ ClassifyData[1]?.name }}
            </div>
            <div class="content">
                <div class="item" v-for="a in ClassifyData[1]?.cates"
                    @click="detail(a.cateId, a.cateName, ClassifyData[1].channel)">
                    <div class="bg">{{ a.cateName }}</div>
                </div>
            </div>
        </div>
        <div class="space"></div>
        <div class="men-list">
            <div class="title">
                <em class="sep"></em>
                {{ ClassifyData[2]?.name }}
            </div>
            <div class="content">
                <div class="item" v-for="a in ClassifyData[2]?.cates" @click="publish(a.cateId, a.cateName)">
                    <div class="bg">{{ a.cateName }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.men-list {
    width: 345rem;
    padding: 15rem;
    margin-bottom: 8rem;

    .sep {
        display: inline-block;
        background: #ED6460;
        border-radius: 3px;
        width: 2.5px;
        height: 12px;
        margin-right: 6px px;
    }

    .title {
        height: 19rem;
        color: #ED6460;
        font-size: 18rem;
        font-weight: bold;
    }

    .content {
        display: flex;
        flex-wrap: wrap;

        .item {
            width: 115rem;
            height: 50rem;
            display: flex;
            align-items: center;

            .bg {
                width: 85rem;
                height: 30rem;
                margin: 0 15rem;
                background-color: #f5f5f5;
                border-radius: 4rem;
                font-size: 14rem;
                text-align: center;
                line-height: 30rem;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
            }
        }
    }
}

.space {
    height: 8rem;
    width: 375rem;
    background-color: #f5f5f5;
}
</style>